<?php 

require 'config/dbconfig.php';


#these simply store posted data into variables
$title = $_POST['title'];
$description = $_POST['desc'];
$private_public = $_POST['private_or_public'];
$how_many_contestants = $_POST['how_many_contestants'];
$how_much_time = $_POST['times'];
$how_many_votes = $_POST['votes'];
//print_r($_SESSION);

#test - view the current session info, uncomment in production
#var_dump($_SESSION);


#saves the id of the logged in user (user who created the challenge) to a variable
$user = $_SESSION['id'];

#test to see posted data, uncomment in production
#echo "TITLE: $title , DESCRIPTION: $description , PRIVATE/PUBLIC: $private_public , HOW MANY CONTESTANTS: $how_many_contestants , HOW MUCH TIME: $how_much_time , HOW MANY VOTES: $how_many_votes , CREATOR ID: $user";
date_default_timezone_set('America/New_York');
if (isset($how_much_time)) {
	$now = date("Y-m-d H:i:s");
	$end_time = date("Y-m-d H:i:s", strtotime(sprintf("+%d hours", $how_much_time)));

}

$query = mysql_query("INSERT INTO `challenges` (challenge_user_id, title, description, amount_of_contestants, private, created_on, ended_on, win_by_votes, win_by_times) VALUES ('$user', '$title', '$description', '$how_many_contestants', '$private_public', '$now', '$end_time', '$how_many_votes', '$how_much_time')") or die(mysql_error());



?>